function execute(name, desc) {
  //1、登录
  login()
  //2、创建用户组
  createUserGroup(name, desc)
  //3、查询新创建的用户组
  searchCreatedUserGroup()
  //4、查找所有调度
  findAllSchedules()
}

function login() {
  var url = "http://localhost:8081/loginOut";

  var params = new HashMap()

  with(Object.bindProperties({}, params)) {
    put("action", "login");
    put("username", "houjinxin");
    put("password", "");
  }

  var headers = new HashMap()

  with(Object.bindProperties({}, headers)) {
    put("Host", "localhost:8081");
    put("Connection", "keep-alive");
    put("Accept", "application/json, text/javascript, */*; q=0.01");
    put("X-Requested-With", "XMLHttpRequest");
    put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36");
    put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    put("Origin", "http://localhost:8081");
    put("Sec-Fetch-Site", "same-origin");
    put("Sec-Fetch-Mode", "cors");
    put("Sec-Fetch-Dest", "empty");
    put("Referer", "http://localhost:8081/loginOut");
    put("Accept-Encoding", "gzip, deflate, br");
    put("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
    put("Cookie", "Idea-dc3bb720=1a9dde01-976f-44f4-b825-15bcf18cce8d; azkaban.failure.message=; azkaban.warn.message=; azkaban.success.message=; history_url=http://localhost:8081/index; JSESSIONID=node014lawohdjnbzh1tbiwzjw4qetn2.node0");

  }
  var result = RequestUtil.post(url, params, headers);
  print(result)
  var sessionId = JSON.parseObject(result).getString("session.id")

  context.sessionId = sessionId
}

function createUserGroup(name, desc) {

  var url = "http://localhost:8081/user_group_manager";

  var params = new HashMap()
  with(Object.bindProperties({}, params)) {
    put("name", name);
    put("action", "create");
    put("description", desc);
  }

  var headers = new HashMap()

  with(Object.bindProperties({}, headers)) {
    put("Host", "localhost:8081");
    put("Connection", "keep-alive");
    put("Accept", "application/json, text/javascript, */*; q=0.01");
    put("X-Requested-With", "XMLHttpRequest");
    put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36");
    put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    put("Origin", "http://localhost:8081");
    put("Sec-Fetch-Site", "same-origin");
    put("Sec-Fetch-Mode", "cors");
    put("Sec-Fetch-Dest", "empty");
    put("Referer", "http://localhost:8081/user_group");
    put("Accept-Encoding", "gzip, deflate, br");
    put("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
    put("Cookie", "Idea-dc3bb720=1a9dde01-976f-44f4-b825-15bcf18cce8d; azkaban.failure.message=; azkaban.warn.message=; azkaban.success.message=; history_url=http://localhost:8081/index; azkaban.browser.session.id=" + context.sessionId + "; userName=houjinxin; digest=FAE317E5E6CF469E76EE3B817F6358AC; JSESSIONID=node0y83vgwe7k8kk16safynnelcay3.node0");

  }
  var result = RequestUtil.post(url, params, headers);

  System.out.println(result);
}

function searchCreatedUserGroup() {

  var url = "http://localhost:8081/user_group";
  var headers = new HashMap()
  with(Object.bindProperties({}, headers)) {
    put("Host", "localhost:8081");
    put("Connection", "keep-alive");
    put("Upgrade-Insecure-Requests", "1");
    put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36");
    put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
    put("Sec-Fetch-Site", "same-origin");
    put("Sec-Fetch-Mode", "navigate");
    put("Sec-Fetch-User", "?1");
    put("Sec-Fetch-Dest", "document");
    put("Referer", "http://localhost:8081/user_group");
    put("Accept-Encoding", "gzip, deflate, br");
    put("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
    put("Cookie", "Idea-dc3bb720=1a9dde01-976f-44f4-b825-15bcf18cce8d; azkaban.failure.message=; azkaban.warn.message=; azkaban.success.message=; history_url=http://localhost:8081/index; azkaban.browser.session.id=" + context.sessionId + "; userName=houjinxin; digest=FAE317E5E6CF469E76EE3B817F6358AC; JSESSIONID=node0y83vgwe7k8kk16safynnelcay3.node0");
  }
  var result = RequestUtil.get(url, new HashMap(), headers)

  _import("org.jsoup.Jsoup")
  var eles = Jsoup.parse(result).select("#project-list li")

  //lambda 表达式的支持
  eles.forEach(function(ele) {
    System.out.println("已创建的组：" + ele.select("h4 a").text())
  });
}

function findAllSchedules(){
  var url = "http://localhost:8081/kdts/schedule/findAllSchedules";
  var params = new HashMap()
  with(Object.bindProperties({}, params)) {
    put("pageSize", "10");
    put("page", "1");
    put("status", "-1");

  }

  var headers = new HashMap()
  with(Object.bindProperties({}, headers)) {
    put("Host", "localhost:8081");
    put("Connection", "keep-alive");
    put("Accept", "*/*");
    put("X-Requested-With", "XMLHttpRequest");
    put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36");
    put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    put("Origin", "http://localhost:8081");
    put("Sec-Fetch-Site", "same-origin");
    put("Sec-Fetch-Mode", "cors");
    put("Sec-Fetch-Dest", "empty");
    put("Referer", "http://localhost:8081/schedule");
    put("Accept-Encoding", "gzip, deflate, br");
    put("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
    put("Cookie", "Idea-dc3bb720=1a9dde01-976f-44f4-b825-15bcf18cce8d; azkaban.failure.message=; azkaban.warn.message=; azkaban.success.message=; history_url=http://localhost:8081/index; JSESSIONID=node0y6rzh1ku7yalym4ysexi20ry2.node0; azkaban.browser.session.id=b7122c56-10d7-4766-9739-0969b7e2b61e; userName=houjinxin; digest=FAE317E5E6CF469E76EE3B817F6358AC");

  }

  var result = RequestUtil.post(url, params, headers)

  System.out.println(result)
}


